package com._520it.member.service.impl;

import com._520it.member.domain.Vip;
import com._520it.member.mapper.VipMapper;
import com._520it.member.page.PageResult;
import com._520it.member.query.VipQueryObject;
import com._520it.member.service.IVipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;

@Service
public class VipServiceImpl implements IVipService {

    @Autowired
    private VipMapper vipMapper;

    @Override
    public int deleteByPrimaryKey(Long id) {
        return vipMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Vip record) {

        //1:设置会员卡状态 0:正常 ,1:挂失
        record.setState(Byte.parseByte("0"));
        //2:设置会员卡初始化密码
        record.setPassword("88888888");
        //3:初始化开卡日期
        record.setBirthday(new Date());
        //4:初始化会员卡号
        record.setCard("88888888");

        return vipMapper.insert(record);
    }

    @Override
    public Vip selectByPrimaryKey(Long id) {
        return vipMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Vip> selectAll() {
        return vipMapper.selectAll();
    }

    @Override
    public int updateByPrimaryKey(Vip record) {
        return vipMapper.updateByPrimaryKey(record);
    }

    @Override
    public PageResult queryPage(VipQueryObject qo) {


        Integer count = vipMapper.queryCount(qo);
        if(count == 0){
            return new PageResult(0, Collections.EMPTY_LIST);
        }

        List<Vip> data = vipMapper.queryData(qo);

        return new PageResult(count,data);

    }
}
